package top.zuli.package01.class14;

/*
三个窗口共同售卖100张火车票
*/
public class WindowTest {
    public static void main(String[] args) {

        Window window1 = new Window("线程1---");
        Window window2 = new Window("线程2---");
        Window window3 = new Window("线程3---");
        window1.start();
        window2.start();
        window3.start();
    }
}
class Window extends Thread{
    public Window(String name){
        super(name);
    }
    private static int ticket = 100;

    @Override
    public void run() {
        while(true){
            if(ticket>0){
                System.out.println(getName()+"卖票,票号:"+ticket);
                try {
                    sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                ticket--;
            }else {
                break;
            }
        }
    }
}